package com.ywx.yypicturebackend.exception;

import com.ywx.yypicturebackend.common.BaseResponse;
import com.ywx.yypicturebackend.common.ResultUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(BusinessException.class)
    public BaseResponse<?> businessExceptionHandler(BusinessException exception){
        log.error("businessException:",exception);
        return ResultUtils.error(exception.getCode(),exception.getMessage());
    }

    @ExceptionHandler(RuntimeException.class)
    public BaseResponse<?> runtimeExceptionHandler(RuntimeException exception){
        log.error("runtimeException:",exception);
        return ResultUtils.error(ErrorCode.SYSTEM_ERROR);
    }



}
